<admintpl file="er" />
<link rel="stylesheet" type="text/css" href="__PUBLIC__/js/ueditor/third-party/video-js/video-js.min.css"/>
<script type="text/javascript" src="__PUBLIC__/js/ueditor/third-party/video-js/video.js"></script>
<script src="http://cdn.bootcss.com/html5media/1.1.8/html5media.min.js"></script>
<script src="http://api.html5media.info/1.1.4/html5media.min.js"></script>
<script>
	document.domain = "xinhuiwen.com";
</script>
</head>
<body>
<?php
	if(isset($add_from) && $add_from == 1)
	{
		$add_from = 1;
	}else
	{
		$add_from = 0;
	}
?>
	<div class="wrap">
		<ul class="nav nav-tabs">
			<!--<li><a href="{:U('Admin/News/index')}">新闻列表</a></li>-->
			<!--<li><a href="{:U('Admin/News/pindex')}">采集新闻</a></li>-->
			<if condition="$add_from eq '0'">
				<li class="active"><a href="#">快捷发布</a></li>
			</if>
			<if condition="$add_from eq 1">
				<li class="active"><a href="{:U('Admin/NewsManage/publish', array('live_id'=>$live_id,'news_id'=>$news_id, $id_type=>$id_val,'add_from'=>1))}">新闻详情</a></li>
				<li><a href="{:U('Admin/live/edit',array('live_id'=>$live_id,'news_id'=>$news_id,$id_type=>$id_val,'add_from'=>1))}">直播详情</a></li>
				<li><a href="{:U('Admin/live/manage', array('news_id'=>$news_id, $id_type=>$id_val,'add_from'=>1))}">管理</a></li>
				<span style="float: right; margin-right:100px;"> <a href="{:U('Admin/news/index', array($id_type=>$id_val))}">返回栏目新闻列表</a></span>
			</if>
		</ul>

	<?php if($return_val == 0){?>

		<iframe src='<?php echo C("cmshost");?>/create/graphic-news?<?php echo $id_type; ?>=<?php echo $id_val; ?>&news_id=<?php echo $news_id; ?>&special_id=<?php echo $special_id; ?>' id="iframepage" name="iframepage" frameBorder="0" width="100%" height="90%" allowfullscreen="true"></iframe>
		<style>
			html, body, .wrap {
				height: 100%;
			}
			.wrap {
				box-sizing: border-box;
			}
		</style>
	<?php }else{ ?>
		<form method="post" class="form-horizontal" id="pub_form" action="{:U('Admin/NewsManage/add_news',array('live_id'=>$live_id,'news_id'=>$news_id,$id_type=>$id_val,'add_from'=>$add_from))}"
			  enctype="multipart/form-data">
			<div class="control-group">
				<label class="span1 control-label" style="width: 90px;">*新闻标题：</label>
				<div class="span3">
					<input type="text" name="title"  style="width: 556px;" value="{$news_info.title}">
				</div>
			</div>
			<div class="control-group">
				<label class="span1 control-label" style="width: 90px;">副标：</label>
				<div class="span3">
					<input type="text" name="subTitle"  style="width: 556px;" value="{$news_info.subtitle}">
				</div>
			</div>
			<div class="control-group">
				<label class="span1 control-label" style="width: 90px;">关键字：</label>
				<div class="span3">
					<input type="text" name="keyword"  style="width: 556px;" value="{$news_info.keywords}">
				</div>
			</div>
			<div class="control-group">
				<label class="span1 control-label" style="width: 90px;">新闻来源：</label>
				<div class="span3">
					<input type="text" name="source"  style="width: 556px;" value="{$news_info.source_name}">
				</div>
			</div>
			<div class="control-group">
				<label class="span1 control-label" style="width: 90px;">权重：</label>
				<div class="span3">
					<input type="text" name="weight"  style="width: 556px;" value="{$news_info.weight}">
				</div>
			</div>
			<div class="control-group">
				<label class="span1 control-label" style="width: 90px;">标签：</label>
				<div class="span3">
					<input type="text" name="tags"  style="width: 556px;" value="{$news_info.tags}">
				</div>
			</div>
			<div class="control-group">
				<label class="span2 control-label" style="width: 90px;">新闻摘要：</label>
				<div class="span7">
					<textarea style="width: 556px; height: 60px;" name="abstract">{$news_info.abstract}</textarea>
				</div>
			</div>
			<?php if($type != '2'){?>
			<div class="control-group">
				<label class="span1 control-label" style="width: 90px;">是否置顶：</label>
				<div class="span3">
					<label class="radio inline" for="lightup_true"> <input type="radio" id="top_status" <if condition="$news_info.top_status eq 1"> checked </if> class="radio" name="top_status" value="1" />是</label> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
					<label class="radio inline" for="lightup_false"> <input type="radio" id="top_status" <if condition="$news_info.top_status eq 0"> checked </if> class="radio" name="top_status" value="0" />否</label>
				</div>
			</div>
			<?php }?>
			<?php if($type == '2'){?>
			<div class="control-group">
				<label class="span1 control-label" style="width: 90px;">专题分栏：</label>
				<div class="span3">
					<select class="select_2" name="special_type" id="special_type" >
						<foreach name="special_column_type_list" item="vo">
							<option value="{$vo.type_id}" <?php if(isset($type_id)){ if($vo['type_id'] == $type_id) echo "selected";}?> >{$vo.name}</option>
						</foreach>
					</select>
				</div>
			</div>
			<?php }else{?>
			<!--本地栏目 无栏目类型-->
			<if condition="$id_type eq 'column_id'">
				<div class="control-group">
					<label class="span1 control-label" style="width: 90px;">栏目类型：</label>
					<div class="span3">
						<select class="select_2" name="column_type" id="column_type" >
							<foreach name="type_list" item="vo">
								<option value="{$vo.type_id}" <?php if($vo['type_id']==$news_info['type_id']) {echo "selected";}?>>
								{$vo.name}</option>
							</foreach>
						</select>
					</div>
				</div>
			</if>

			<if condition="$special_column_list ">
				<div class="control-group">
					<label class="span1 control-label" style="width: 90px;">专题分栏：</label>
					<div class="span3">
						<select class="select_2" name="special_column_type" id="special_column_type" >
							<foreach name="$special_column_list" item="vo">
								<option value="{$vo.type_id}" <?php if($vo['type_id']==$news_info['type_id']) {echo "selected";}?>>
								{$vo.name}</option>
							</foreach>
						</select>
					</div>
				</div>
			</if>
			<?php } ?>
			<div class="control-group">
				<label class="span1 control-label" style="width: 90px;">封面图片：</label>
				<div class="span4 wrapper">
					<div id="uploader-image">
						<div id="fileList" class="uploader-list">
							<div id="imageDiv" class="file-item thumbnail" style="width:150px;height: 150px;">
								<?php
										if(!empty($news_info['cover_image'])){
									?>
								<img id="imagePreview" src="{$news_info.cover_image}" style="width:150px;height: 140px;">
								<input style="display:none;" type="hidden" name="cover_image" value="{$news_info.cover_image}" >
								<?php
										}else{
										?>
								<img id="imagePreview" src="__PUBLIC__/images/furley_bg.png" style="width:150px;height: 140px;">
								<?php
										}
										?>
								<div id="picker" class="info">选择图片&nbsp;&nbsp;&nbsp;&nbsp;</div>
								<input style="display:none;" type="file" id="imageFile" name="imageFile" >

							</div>
						</div>
					</div>
				</div><div style="color:red;float:left;margin-top:140px">*列表缩略  尺寸：270*186  格式：JPG/PNG</div>
			</div>
			<div class="control-group">
				<label class="span2 control-label" style="width: 90px;">新闻正文：</label>
				<div class="span9">
					<script type="text/plain" id="content" name="newsContent"><?php echo json_decode($news_info['content'])?></script>
				</div>
			</div>
			<div class="jairu" style="margin-left: 150px">
				<a onclick="insertHtml()">插入给定的内容</a>
			</div>
			<div class="control-group">
				<label class="span1 control-label" style="width: 90px;">是否添加图片水印：</label>
				<div class="span3">
					<label class="radio inline" for="lightup_true"> <input type="radio" id="water_true" class="radio" name="water" value="1"  <if condition="$news_info.is_watermark eq 1"> checked </if> />  开启</label> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
					<label class="radio inline" for="lightup_false"> <input type="radio" id="water_false"  class="radio" name="water" value="0"  <if condition="$news_info.is_watermark eq 0">checked </if> />关闭</label>
                </div>
			</div>
			<div class="control-group">
				<label class="span1 control-label" style="width: 90px;">发布渠道：</label>
				<div class="span3">
					<label class="radio inline" for="lightup_true"> <input type="checkbox" <if condition="$news_info.app_pub eq 1"> checked </if> id="pub" class="radio" name="pub[]" value="1" />APP</label> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
					<label class="radio inline" for="lightup_false"> <input type="checkbox" id="pub" <if condition="$news_info.web_pub eq 1"> checked </if>  class="radio" name="pub[]" value="2" />门户</label>
				</div>
			</div>
			<div class="control-group">
				<label class="span1 control-label" style="width: 90px;">内部链接：</label>
				<div class="span3" style="width:556px">
					<input type="text" name="reference"  style="width: 556px;" value="<?php if($news_info['reference_id'] && $news_info['reference_type']) echo "id=".$news_info['reference_id']."&type=".$news_info['reference_type'];?>">
				</div>
				<?php if($news_info['reference_id'] && $news_info['reference_type']){ ?>
				<div style="float: left; margin-left: 50px;"><a href="<?php echo U('NewsManage/publish', array('news_id'=>$news_info['reference_id']));?>">维护新闻</a></div>
				<?php } ?>
			</div>

			<div class="control-group">
				<label class="span1 control-label" style="width: 90px;">直播ID：</label>
				<div class="span3" style="width:556px">
					<input type="text" name="role_live_id"  style="width: 556px;" value="<?php if($news_info['live_id']) echo $news_info['live_id'];?>" <?php if($news_info['live_id']){ ?> readonly='readonly' <?php } ?> >
				</div>
			</div>

			<div class="control-group">
				<label class="span1 control-label" style="width: 90px;">投票ID：</label>
				<div class="span3" style="width:556px">
					<input type="text" name="vote_id"  style="width: 556px;" value="<?php if($news_info['vote_id']) echo $news_info['vote_id'];?>" <?php if($news_info['vote_id']){ ?> readonly='readonly' <?php } ?> >
				</div>
			</div>

			<div class="control-group">
				<label class="span1 control-label" style="width: 90px;">阅读原文：</label>
				<div class="span3">
					<input type="text" name="outer_url"  style="width: 556px;" value="{$news_info.outer_url}">
					<label  for="lightup_false"> <input type="checkbox" id="outer_url_pub" <if condition="$news_info.outer_url_ishot eq 1"> checked </if>  class="radio" name="outer_url_pub" value="1" />设为新闻链接</label>
				</div>
				<div class="control-group">
					<label class="span1 control-label" style="width: 90px;">外链：</label>
					<div class="span3">
						<input type="text" name="outer_url"  style="width: 556px;" value="{$news_info.external_link}">
					</div>
				</div>
			<?php if(!empty($news_info['relation'])){ ?>

				<?php for($i=0; $i<4;++$i){ ?>
					<?php if($news_info['relation'][$i]){ ?>
					<div class="control-group" id="pictureHtml">
						<label class="span1 control-label" style="width: 90px;">关联新闻：</label>
						<div class="span3" style="float: left;">
							<input type="text" name="news_recommend[]"  style="width: 556px;" value="<?php echo "id=".$news_info['relation'][$i]['recommend_id']."&type=".$news_info['relation'][$i]['type'].'&weight='.$news_info['relation'][$i]['weight'];?>">
						</div>
					</div>
					<?php }else{ ?>
					<div class="control-group" id="pictureHtml">
						<label class="span1 control-label" style="width: 90px;">关联新闻：</label>
						<div class="span3" style="float: left;">
							<input type="text" name="news_recommend[]"  style="width: 556px;" value="">
						</div>
					</div>
					<?php } ?>
				<?php } ?>

			<?php }else{ ?>

				<div class="control-group">
					<label class="span1 control-label" style="width: 90px;">关联新闻：</label>
					<div class="span3" style="width:556px">
						<input type="text" name="news_recommend[]"  style="width: 556px;" value="">
					</div>
				</div>
				<div class="control-group">
					<label class="span1 control-label" style="width: 90px;">关联新闻：</label>
					<div class="span3" style="width:556px">
						<input type="text" name="news_recommend[]"  style="width: 556px;" value="">
					</div>
				</div>
				<div class="control-group">
					<label class="span1 control-label" style="width: 90px;">关联新闻：</label>
					<div class="span3" style="width:556px">
						<input type="text" name="news_recommend[]"  style="width: 556px;" value="">
					</div>
				</div>
				<div class="control-group">
					<label class="span1 control-label" style="width: 90px;">关联新闻：</label>
					<div class="span3" style="width:556px">
						<input type="text" name="news_recommend[]"  style="width: 556px;" value="">
					</div>
				</div>
			<?php } ?>

			<input type="hidden" name="special_id" value="<?php echo isset($special_id) ? $special_id : '0'?>">
			<input type="hidden" name="news_id" value="{$news_id}">
			<input type="hidden" name="{$id_type}"  value="{$id_val}" >
			<input type="hidden" name="type"  value="{$news_info.type}">
			<input type="hidden" name="is_special" value="{$type}">
			<input type="hidden" id="img_video" value="__PUBLIC__/images/error.jpg">
			<div class="form-actions" style="padding-left:260px;">
				<button type="button" id="quick_publish" class="btn">保存</button>
				&nbsp;&nbsp;
				<if condition="$type eq 2">
					<a class="btn" href="{:U('Admin/Special/index',array('news_id'=>$special_id,$id_type=>$id_val))}">{:L('BACK')}</a>
					<else/>
					<a class="btn" href="{:U('Admin/News/index?'.$id_type.'='.$id_val)}">{:L('BACK')}</a>
				</if>

			</div>
		</form>
	<?php }?>
	</div>

	<script src="__PUBLIC__/js/common.js"></script>
	<?php if($return_val == 1){?>
		<script type="text/javascript" src="__PUBLIC__/js/content_addtop.js"></script>
		<script type="text/javascript">
			//编辑器路径定义
			var editorURL = GV.DIMAUB;
		</script>



		<script type="text/javascript" src='__PUBLIC__/js/ueditor/ueditor.config.js?time=<?php echo time();?>'></script>


		<script type="text/javascript" src="__PUBLIC__/js/ueditor/ueditor.all.min.js"></script>

		<script type="text/javascript" >
			$(document).ready(function () {
				$("#edui1_iframeholder").html(<?php echo $news_info['content'];?>);
				$('#upperId').change(function () {
					$.get('{:U("Admin/News/ajax_get_cate")}' + '&upperId=' + $('#upperId').val(), function (data) {
						var html = '<option value="0">--无--</option>';
						if(data['state']=="success"){
							html = '<option value="-1">全部</option>';
							for (var a in data.newsCategoryList) {
								html += '<option value="' + data.newsCategoryList[a].cateId + '">' + data.newsCategoryList[a].cateName + '</option>';
							}
						}
						$('#categoryId').html(html);
					});
				});
				$('#channelId').change(function () {
					$.get('{:U("Admin/News/ajax_get_subject")}' + '&cateId=' + $('#channelId').val(), function (data) {
						var html = '<option value="0">--无--</option>';
						if(data['state']=="success"){
							html = '<option value="-1">全部</option>';
							for (var a in data.tagList) {
								html += '<option value="' + data.tagList[a].tagTitle + '">' + data.tagList[a].tagTitle + '</option>';
							}
						}
						$('#subjectId').html(html);
					});
				});
			});
			$(function() {

				//编辑器
				editorcontent = new baidu.editor.ui.Editor();

				editorcontent.render('content');
				try {
					editorcontent.sync();
				} catch (err) {
				}
				//增加编辑器验证规则
				jQuery.validator.addMethod('editorcontent', function() {
					try {
						editorcontent.sync();
					} catch (err) {
					}
					return editorcontent.hasContents();
				});
				var form = $('form.js-ajax-forms');
				//ie处理placeholder提交问题
				if ($.browser.msie) {
					form.find('[placeholder]').each(function() {
						var input = $(this);
						if (input.val() == input.attr('placeholder')) {
							input.val('');
						}
					});
				}
				////-------------------------
			});

			function insertHtml() {
				var value = prompt('插入html代码', '');
				var s = value.indexOf(".mp4") ;
				var img_video = $("#img_video").val();
				if(s == -1){ //不是 mp4格式的
					value = value;
				}else{
					value = '<video src="'+value+'" style="width:100%" controls="controls" poster="'+img_video+'" class="videoplay"><\/video>';
		//				value = '<a href="'+value+'" target="_self"> <img src="'+value+'" title="Penguins.jpg" alt="Penguins.jpg"/> </a>';
				}
				UE.getEditor('content').execCommand('insertHtml', value)
			}

			function html5Reader(file, previewId){
				var file = file.files[0];
				var reader = new FileReader();
				reader.readAsDataURL(file);
				reader.onload = function(e){
					$('#'+previewId).attr('src', this.result);
				}
			}
			function image_change(fileId, previewId) {
				var pic = document.getElementById(previewId),
						file = document.getElementById(fileId);

				var ext = file.value.substring(file.value.lastIndexOf(".")+1).toLowerCase();

				// gif在IE浏览器暂时无法显示
				if(ext != 'png' && ext != 'jpg' && ext != 'jpeg'){
					alert("图片的格式必须为png或者jpg或者jpeg格式！");
					return;
				}
				var isIE = navigator.userAgent.match(/MSIE/)!= null,
						isIE6 = navigator.userAgent.match(/MSIE 6.0/)!= null;

				if(isIE) {
					file.select();
					var realLocalPath = document.selection.createRange().text;

					// IE6浏览器设置img的src为本地路径可以直接显示图片
					if (isIE6) {
						pic.src = realLocalPath;
					}else {
						// 非IE6版本的IE由于安全问题直接设置img的src无法显示本地图片，但是可以通过滤镜来实现
						pic.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod='image',src=\"" + realLocalPath + "\")";
						// 设置img的src为base64编码的透明图片 取消显示浏览器默认图片
						pic.src = '';
					}
				}else {
					html5Reader(file, previewId);
				}
			}

			$("#picker").click(function(){
				$("#imageFile").click();
			});

			$("#imageFile").change(function(){
				image_change('imageFile', 'imagePreview');
			});
			/* Dom添加删除操作 */

			function copyHtml(){
				var addHtml=$("#pictureHtml").html();

				var pictureMaxValue=$("#pictureMax").val();
				var newMaxValue=parseInt(pictureMaxValue)+1;
				$("#pictureMax").val(newMaxValue);

				var newImgId="imageUrl"+newMaxValue;
				var pickerId="picker"+newMaxValue;
				var imageUrl="imageUrl"+newMaxValue+"_preview";
				var imageFileId="FileImage"+newMaxValue;
				var image      ="imageFile";

				var add2Html=addHtml.replace(new RegExp("imageCopy","gm"),newImgId);
				add2Html1=add2Html.replace(new RegExp("picker","gm"),pickerId);
				add2Html2=add2Html1.replace(new RegExp("imageUrl_preview","gm"),imageUrl);
				add2Html3=add2Html2.replace(new RegExp("FileImage","gm"),imageFileId);
				add2Html5=add2Html3.replace(new RegExp("imageFiles","gm"),image);
				add2Html4="<div class='control-group' id='pictureHtml"+newMaxValue+"'  >"+add2Html5+"</div>";
				$("#pictureHtml").before(add2Html4);

				var pictureCount=$("#pictureCount").val();
				var newCount=parseInt(pictureCount)+1;
				$("#pictureCount").val(newCount);
			}
			function removeHtml($obj){
				$($obj).parent().parent().remove();
				var pictureCount=$("#pictureCount").val();
				var newCount=parseInt(pictureCount)-1;
				$("#pictureCount").val(newCount);
			}


		</script>
	<?php } ?>

</body>
</html>